package com.easypan.service.impl;

import com.easypan.entity.enums.FileTypeEnums;
import com.easypan.service.FileProcessingStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cyb
 * @create 2024-12-17-19:10
 * @description  创建上下文类
 */
public class FileProcessorContext {

    private final Map<FileTypeEnums, FileProcessingStrategy> strategyMap = new HashMap<>();

    public FileProcessorContext() {
        registerStrategy(FileTypeEnums.VIDEO, new VideoProcessingStrategy());
        registerStrategy(FileTypeEnums.IMAGE, new ImageProcessingStrategy());
        // 注册其他类型的策略...
    }

    public void registerStrategy(FileTypeEnums type, FileProcessingStrategy strategy) {
        strategyMap.put(type, strategy);
    }

    public void processFile(FileTypeEnums fileTypeEnum, String fileId, String targetFilePath, String month, String currentUserFolderName, String targetFolderName) {
        FileProcessingStrategy strategy = strategyMap.get(fileTypeEnum);
        if (strategy != null) {
            strategy.processFile(fileId, targetFilePath, month, currentUserFolderName, targetFolderName);
        } else {
            throw new IllegalArgumentException("No processing strategy found for file type: " + fileTypeEnum);
        }
    }
}
